<?php

/**
 * ContactForm class.
 * ContactForm is the data structure for keeping
 * contact form data. It is used by the 'contact' action of 'SiteController'.
 */
class Mail extends CFormModel {

    public $id;
    public $name;
    public $mail_to;
    public $mail_from = "sale@vnsupermark.com";
    public $subject;
    public $content;

    /**
     * Declares the validation rules.
     */
    public function rules() {
        return array(
            array('mail_to, mail_from, content', 'required'),
        );
    }

    /**
     * Declares customized attribute labels.
     * If not declared here, an attribute would have a label that is
     * the same as its name with the first letter in upper case.
     */
    public function attributeLabels() {
        return array(
            'mail_to' => 'Mail To',
            'mail_from' => 'Mail From',
            'content' => 'Content',
        );
    }

    public function sendMail($m) {

        $message = new YiiMailMessage();
        //this points to the file test.php inside the view path
        $message->view = "test";
        $params = array('myMail' => $m);
        $message->subject = $m->subject;
        $message->setBody($params, 'text/html');
        $message->addTo($m->mail_to);
        //$message->from = $m->mail_from; 
        $message->setFrom($m->mail_from, 'VNsupermark Support');

        Yii::app()->mail->send($message);
    }

}
